<?php
/* 	These code was generated using phpCIGen v 0.1.b (24/06/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id

	+ Module  		: m_shift View
	+ Description	: For record view
	+ Filename 		: v_m_shift.php
 	+ creator  		: 
 	+ Created on 31/May/2011 09:41:28

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/**
 * 
 */
/* declare function */
var t_lap_sale_permrktg_ColumnModel;
var t_lap_sale_permrktg_ListEditorGrid;
var t_lap_sale_permrktg_filterForm;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Reset";
var BTN_SUMMARY="Rekap";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh Data";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Lanjut Data";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (hmtl)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

/* on ready fuction */
Ext.onReady(function(){
	Ext.QuickTips.init();	/* Initiate quick tips icon */
	
	/* Function for Retrieve DataStore */
	var lap_sale_permrktg_tableDataStore = new Ext.data.GroupingStore({
		id: 'lap_sale_permrktg_tableDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_lap_sale_permrktg&m=get_list',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
		    {name: 'order_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'order_date'},
		    {name: 'm_customer_id', type: 'int', mapping: 'm_customer_id'},
		    {name: 'customer_name', type: 'string', mapping: 'customer_name'},
		    {name: 'm_staff_id', type: 'int', mapping: 'm_staff_id'},
		    {name: 'staff_name', type: 'string', mapping: 'staff_name'},
		    {name: 'order_code', type: 'string', mapping: 'order_code'},
		    {name: 'orderdet_qty', type: 'float', mapping: 'orderdet_qty'},
		    {name: 'orderdet_detail', type: 'string', mapping: 'orderdet_detail'},
		    {name: 'orderdet_price', type: 'float', mapping: 'orderdet_price'},
		    {name: 'jumlah', type: 'float', mapping: 'jumlah'}
		    
		]),
		sortInfo:{field: 'order_code', direction: "ASC"},
		groupField: 'm_staff_id'
	});
        
	/* End of Function */
	
	function toDate(dStr,format) {
		var now = new Date();
		if (format == "h:m") {
	 		now.setHours(dStr.substr(0,dStr.indexOf(":")));
	 		now.setMinutes(dStr.substr(dStr.indexOf(":")+1));
	 		now.setSeconds(0);
	 		return now;
		}else 
			return "Invalid Format";
	}

	/* Field for search */
	var lap_sale_permrktg_MonthField= new Ext.form.DateField({
		id: 'lap_sale_permrktg_MonthField',
		fieldLabel: 'Tanggal',
		editable: false,
		allowBlank: false,
		width: 90,
		format: 'M Y'
	});

	var lap_sale_permrktg_startDateField= new Ext.form.DateField({
		id: 'lap_sale_permrktg_startDateField',
		fieldLabel: 'Tanggal',
		editable: false,
		width: 90,
		format: 'd-m-Y'
	});
	
	var lap_sale_permrktg_endDateField= new Ext.form.DateField({
		id: 'lap_sale_permrktg_endDateField',
		editable: false,
		width: 90,
		format: 'd-m-Y'
	});
    /* End of Function */

	
	function lap_sale_permrktg_search_table(){
		if(is_lap_sale_permrktg_table_bybayar_form_valid()){
			//lap_sale_permrktg_tableDataStore.setBaseParam('bulan', lap_sale_permrktg_MonthField.getValue().format('Y-m'));
			lap_sale_permrktg_tableDataStore.setBaseParam('tgl_start', lap_sale_permrktg_startDateField.getValue());
			lap_sale_permrktg_tableDataStore.setBaseParam('tgl_end', lap_sale_permrktg_endDateField.getValue());
			lap_sale_permrktg_tableDataStore.load();
		}else{
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	function is_lap_sale_permrktg_table_bybayar_form_valid(){
		return (true && lap_sale_permrktg_startDateField.isValid() && lap_sale_permrktg_endDateField.isValid() );
	}

	function lap_sale_permrktg_print_table(){
		if(is_lap_sale_permrktg_table_bybayar_form_valid()){
			Ext.Ajax.request({
				waitMsg: 'Please Wait...',
				url: 'index.php?c=c_lap_sale_permrktg&m=print_list',
				params: {
					//bulan: lap_sale_permrktg_MonthField.getValue().format('Y-m')
					tgl_start: lap_sale_permrktg_startDateField.getValue(),
					tgl_end: lap_sale_permrktg_endDateField.getValue()
				},
				success: function(response){
				  	var result=eval(response.responseText);
				  	switch(result){
				  	case 1:
						window.open('./print/t_lap_sale_permrktg.html','laporan_tagihan','height=600,width=800,resizable=1,scrollbars=1, menubar=0');
						break;
				  	default:
						Ext.MessageBox.show({
							title: 'Warning',
							msg: FAILED_PRINT,
							buttons: Ext.MessageBox.OK,
							animEl: 'save',
							icon: Ext.MessageBox.WARNING
						});
						break;
				  	}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});
		}else{
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}

	}
	/* END Event Handler */
	
	Ext.ux.grid.GroupSummary.Calculations['total'] = function(v, record, field){
		return v + record.data.jumlah;
    };
	
	var summary = new Ext.ux.grid.HybridSummary();
	
	/* START GridPanel For Table by Cust */
	lap_sale_permrktg_tableColumnModel = new Ext.grid.ColumnModel([
 		{
 			header: 'Tanggal Order',
 			dataIndex: 'order_date',
 			width: 90,
 			sortable: false,
 			renderer: Ext.util.Format.dateRenderer('d-m-Y')
 		},
 		{
 			header: 'staff_id',
 			dataIndex: 'm_staff_id',
 			width: 150,
 			sortable: false,
 			hidden:true
 		},
 		{
 			header: 'No. Order',
 			dataIndex: 'order_code',
 			width: 150,
 			sortable: false
 		},
 		{
 			header: 'Company',
 			dataIndex: 'customer_name',
 			width: 150,
 			sortable: false
 		},
 		{
 			header: 'Nilai Order',
 			dataIndex: 'jumlah',
 			width: 90,
 			align: 'right',
 			renderer: function(val){
				return '<span>'+Ext.util.Format.number(val,'0,000.00')+'</span>';
			},
 			sortable: false,
 			summaryType: 'total',
			summaryRenderer: function(val){
				return '<span>'+Ext.util.Format.number(val,'0,000.00')+'</span>';
			}
 		}
	]);
	
	var lap_sale_permrktg_tableListGrid =  new Ext.grid.GridPanel({
		id: 'lap_sale_permrktg_tableListGrid',
		renderTo: 'el_lap_sale_permrktg_filter',
		autoHeight: true,
		store: lap_sale_permrktg_tableDataStore, // DataStore
		cm: lap_sale_permrktg_tableColumnModel, // Nama-nama Columns
		enableColLock:false,
		//frame: true,
		plain: true,
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		//viewConfig: { forceFit:true },
		view: new Ext.grid.GroupingView({
            forceFit:true,
            showGroupName: false,
            enableNoGroups:false,
			enableGroupingMenu:false,
            hideGroupedColumn: true,
            //groupTextTpl: '{text}: ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
           	groupTextTpl: 'Marketing: {[ values.rs[0].data["staff_name"] ]} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
        }),
		plugins: summary,
	  	width: 980,
		/* Add Control on ToolBar */
	  	tbar: [{xtype:'label', text: 'Dari Tanggal: '} ,{xtype:'spacer', width: 10} ,lap_sale_permrktg_startDateField
			,{xtype:'spacer', width: 5} ,{xtype:'label', text: 'Sampai Tanggal: '} ,{xtype:'spacer', width: 10} ,lap_sale_permrktg_endDateField
			,'-' ,{
				text: 'Tampilkan',
				tooltip: BTN_REFERSH_TOOLTIP,
				handler: lap_sale_permrktg_search_table,
				iconCls:'icon-refresh'
			},'-' ,{
				text: 'Cetak',
				tooltip: BTN_PRINT_TOOLTIP,
				handler: lap_sale_permrktg_print_table,
				iconCls:'icon-print'
			}]
	});
	/* END GridPanel For Table by Cust */
	
        
	var lap_sale_permrktg_tableCustTab = {
		id: 'lap_sale_permrktg_tableCustTab',
		title: 'Laporan Pelanggan',
		//layout: 'fit',
		autoHeight: true,
		items: lap_sale_permrktg_tableListGrid
	};

  	categoriesTabPanel = new Ext.TabPanel({
        //renderTo: 'el_lap_sale_permrktg_filter',
        activeTab: 0,
        width:1200,
        //height:450,
        frame:true,
        defaults:{autoScroll: true},
        items:[lap_sale_permrktg_tableCustTab]
    });
});
</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div id="el_lap_sale_permrktg_filter"></div>
</div>
</body>
</html>